package com.woniuxy.microaftersaleserver.customservicemag.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.microaftersaleserver.customservicemag.mapper.CustomMapper;
import com.woniuxy.microaftersaleserver.customservicemag.service.ICustomService;
import com.woniuxy.microcommonserver.bean.aftersales_cyx.ConsultGoods;
import com.woniuxy.microcommonserver.bean.aftersales_cyx.CustomService;
import com.woniuxy.microcommonserver.pageHelper.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Transactional(readOnly = true)
@Service
public class CustomServiceImpl implements ICustomService {

    @Resource
    private CustomMapper customMapper;

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @Override
    public void addCustomerService(CustomService customService) {
        customMapper.addCustomerService(customService);
    }

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @Override
    public void updateCustomService(CustomService customService) {
        customMapper.updateCustomService(customService);
    }

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @Override
    public void deleteCustomService(int id) {
        customMapper.deleteCustomService(id);
    }

    @Override
    public PageInfo<CustomService> findByPage(PageRequest request, CustomService customService) {
        //System.out.println("============="+customMapper.findByPage(pageRequest,customService));

        PageInfo<CustomService> pageInfo= PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->customMapper.findByPage(request,customService));
        System.out.println("===================="+pageInfo);
        return pageInfo;
    }

    @Override
    public List<CustomService> findByParams(CustomService customService) {
        return customMapper.findByParams(customService);
    }

}
